﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Shared.Dtos.Common
@using Skoruba.IdentityServer4.Admin.UI.Configuration.Constants
@using Skoruba.IdentityServer4.Admin.UI.Helpers
@model Skoruba.IdentityServer4.Admin.BusinessLogic.Dtos.Log.LogsDto
@inject IViewLocalizer Localizer

@{
    ViewBag.Title = Localizer["PageTitle"];
    Layout = "_Layout";
}

<div class="row">
    <div class="col-12 mb-3 text-center mt-1">
        <h2><span class="oi oi-bug" title="Error Logs" aria-hidden="true"></span> @Localizer["PageTitle"]</h2>
    </div>
</div>


<div class="col-12">
    <div asp-validation-summary="All" class="text-danger"></div>
</div>

<form asp-area="@CommonConsts.AdminUIArea" class="error-log-form" asp-controller="Log" asp-action="DeleteLogs">
    <div class="d-flex flex-row mt-3 justify-content-end mb-3">
        <div class="p-2">
            <a href="#" class="btn btn-danger error-log-delete-button">
                @Localizer["DeleteButton"]
            </a>
        </div>
        <div class="p-1">
            <!--Date Picker-->
            <div class="datepicker input-group date">
                <input asp-for="DeleteOlderThan" autocomplete="off" type="text" class="form-control">
                <div class="input-group-append">
                    <span class="input-group-text"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="deleteLogsModal" tabindex="-1" role="dialog" aria-labelledby="deleteLogsModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="deletePersistedGrantsModalLabel">@Localizer["DeleteDialogTitle"]</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    @Localizer["DeleteDialogMessage"]
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-danger">@Localizer["DeleteDialogYes"]</button>
                    <button type="button" class="btn btn-outline-primary" data-dismiss="modal">@Localizer["DeleteDialogNo"]</button>
                </div>
            </div>
        </div>
    </div>
</form>

<div class="row">
    <div class="col-12">
        @await Html.PartialAsync("Common/Search", new Search { Action = "ErrorsLog", Controller = "Log" })
    </div>
</div>

<div class="row">
    <div class="col-12">
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th></th>
                        <th>@Localizer["TableLevel"]</th>
                        <th>@Localizer["TableLogged"]</th>
                        <th>@Localizer["TableMessage"]</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var log in Model.Logs)
                    {
                        <tr>
                            <td><a href="#" data-error-id="@log.Id" class="btn btn-primary btn-error-detail">@Localizer["TableShowDetail"]</a></td>
                            <td>@log.Level</td>
                            <td>
                                <span class="local-datetime" title="@log.TimeStamp" data-utc="@log.TimeStamp.GetEpochTicks()" data-toggle="tooltip" data-placement="top">
                                    @log.TimeStamp
                                </span>
                                <span class="oi oi-clock" title="@log.TimeStamp" data-toggle="tooltip" data-placement="top"></span>
                            </td>
                            <td>@log.Message</td>
                        </tr>
                        <tr class="row-error-detail d-none" data-error-id="@log.Id">
                            <td colspan="4" data-error-json="@log.LogEvent"></td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-12">
        @await Html.PartialAsync("Common/Pager", new Pager { Action = "ErrorsLog", PageSize = Model.PageSize, TotalCount = Model.TotalCount, EnableSearch = true, Search = ViewBag.Search })
    </div>
</div>